//app.js
App({
    onLaunch: function () {
      
    },
    getUserInfo: function (cb) {
        var that = this
        if (this.globalData.userInfo) {
            typeof cb == "function" && cb(this.globalData.userInfo)
        } else {
            //调用登录接口
            wx.login({
                success: function () {
                    wx.getUserInfo({
                        success: function (res) {
                            that.globalData.userInfo = res.userInfo
                            typeof cb == "function" && cb(that.globalData.userInfo)
                        }
                    })
                }
            })
        }
    },
    getSystemInfo: function (cb) {
        var that = this
        if (that.globalData.systemInfo) {
            typeof cb == "function" && cb(that.globalData.systemInfo)
        } else {
            wx.getSystemInfo({
                success: function (res) {
                    that.globalData.systemInfo = res
                    typeof cb == "function" && cb(that.globalData.systemInfo)
                }
            })
        }
    },
    globalData: {
        userInfo: null,
        systemInfo: null
    },
    /**
     * 数字千位符格式化
     */
    toThousands:function(num){
      return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
    },
    /**
     * 缓存form_id
     */
    cacheFormIDs:function(id){
      // console.log('进来了...')
      //缓存
        var form_ids = wx.getStorageSync('form_ids')
        if (form_ids) {
          var form_ids_arr = form_ids.split(',')
          if (form_ids_arr.length >= 10){ //超过10个元素
            //去掉第一个，把新的添加进来
            form_ids_arr.shift();
          }

          //合并，并把新的加在后面
          var form_ids_str = form_ids_arr.join(',') + ',' + id;
          //缓存
          wx.setStorage({
            key: "form_ids",
            data: form_ids_str
          })

        }else{
          //缓存起来
          wx.setStorage({
            key: "form_ids",
            data: id
          })
        }
   
    }
})
